package com.zqh.apiuserregister.service.impl;

import com.zqh.apiuserregister.service.UserRegisterService;
import com.zqh.myfmmall.clients.UserQueryClient;
import com.zqh.myfmmall.clients.UserSaveClient;
import com.zqh.myfmmall.rowbeans.entity.Users;
import com.zqh.myfmmall.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户 (Users)表服务实现类
 *
 * @author KONO 曾淇杭哒！
 * @since 2022-01-20 02:35:50
 */
@Service("userRegisterService")
public class UserRegisterServiceImpl implements UserRegisterService{
    @Autowired
    private UserSaveClient userSaveClient;
    @Autowired
    private UserQueryClient userQueryClient;

    @Override
    public Result register(Users user) {
        Result result = userQueryClient.queryUser(user);
        if (!result.getSuccess()){
            return Result.internalServerError();
        }
        return result.getData() == null ? userSaveClient.saveUser(user) : Result.fail("用户名已存在");
    }
}

